package com.linzelin.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/Login")
public class LoginContorller {

    @RequestMapping("/login")
    public String login(String username, String password, HttpSession session) {
        System.out.println("======username=" + username);
        System.out.println("======password=" + password);
        if ("lin".equals(username)) {
            if ("123".equals(password)) {
                session.setAttribute("user", username);
                return "main";
            }
        }
        session.setAttribute("msg", "登录失败,请校验密码或账户名");
        return "login";
    }

    @RequestMapping("/goLogin")
    public String goLogin() {
        return "login";
        //跳转回登录界面
    }

    @RequestMapping("/goMain")
    public String goMain() {
        return "main";
        //跳转到首页
    }

    @RequestMapping("/unLogin")
    public String unLogin(HttpSession session) {
        session.removeAttribute("user");
        return "login";
    }
}
